﻿using System;
using System.Data.SqlClient;
using System.Windows.Forms;
using Elkomp;

namespace MedicinskiUslugi {

	public partial class frmCenovnik : FormaBrowse {
		SqlConnection con = new SqlConnection();
		SqlCommand com = new SqlCommand();

		public frmCenovnik() {
			InitializeComponent();
			btnOk.Visible = false;
		}

		public frmCenovnik( bool zoom ) {
			InitializeComponent();
			btnOk.Visible = true;
			zoom = true;
		}

		private void SelcectionCHanged( object sender, EventArgs e ) {
			if ( this.tblCenovnikGrid.CurrentRow != null ) {
				dr = this.medicinskiUslugiDataSet.tblCenovnik[this.tblCenovnikGrid.CurrentRow.Index];
			}
		}

		public override void NovZapis( object sender, EventArgs e ) {
			this.tblCenovnikGrid.Insert();
			base.NovZapis( sender, e );
		}

		public override void IzmeniZapis( object sender, EventArgs e ) {
			this.tblCenovnikGrid.Edit();
			base.IzmeniZapis( sender, e );
		}

		private void frmCenovnik_Load( object sender, EventArgs e ) {
			Navigator.BindingSource = tblCenovnikBindingSource;
			this.tblCenovnikTableAdapter.Fill( this.medicinskiUslugiDataSet.tblCenovnik );
		}

		private void btnPrebaraj_Click( object sender, EventArgs e ) {
			this.tblCenovnikTableAdapter.Fill( this.medicinskiUslugiDataSet.tblCenovnik );

			if ( EkonomskaEdinica.read ) {
				this.tblCenovnikBindingSource.Filter = " EkonomskaEdinica_Id =" + EkonomskaEdinica.ret2;
			}
		}

		private void tblCenovnikGrid_DataInsert() {
			this.tblCenovnikTableAdapter.Fill( this.medicinskiUslugiDataSet.tblCenovnik );
		}

		public override void IzbrisiZapis( object sender, EventArgs e ) {
			if ( this.tblCenovnikGrid.CurrentRow != null ) {
				DialogResult opc;
				opc = MessageBox.Show( "Дали сте сигурни ?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question );
				if ( opc == DialogResult.Yes ) {
					this.tblCenovnikGrid.Rows.Remove( tblCenovnikGrid.CurrentRow );
					this.tableAdapterManager.UpdateAll( this.medicinskiUslugiDataSet );
				}
			}

			base.IzbrisiZapis( sender, e );
		}

		private void EkonomskaEdinica_DataRead() {
		}
	}
}